import 'view-ui-plus/dist/styles/viewuiplus.css'
import '/src/iconfont.css'
import { createApp ,inject,provide,ref} from 'vue'
import App from './App.vue'

let app = createApp(App)
// 关闭警告
app.config.warnHandler = () => null;


import ROUTER from './router/main.js'
app.use(ROUTER)


import ViewUIPlus from 'view-ui-plus'
app.use(ViewUIPlus)

import naive from 'naive-ui'
app.use(naive)

import ArcoVue from '@arco-design/web-vue';
import '@arco-design/web-vue/dist/arco.css';
app.use(ArcoVue);

import piniaPersist from 'pinia-plugin-persist'
import { createPinia } from 'pinia'
const pinia = createPinia()
pinia.use(piniaPersist)
app.use( pinia)
// 自定义全局css
import '/src/static/css/alert.css'

// 是否开启全局导航
let show_global_button = ref(Number(localStorage.getItem("show_global_button")))
app.provide('global_button', show_global_button)



// 分配仓库
import { provide_user ,provide_community,provide_music,provide_chat} from './store/provide.js'
provide_user(app)
provide_community(app)
provide_music(app)
provide_chat(app)

// 注入nosql
import ChatCacheDB from './static/js/indexdb/chat.js'
const indexdbparams = {
  dbName: "myChatCache",       // 数据库名称
  cacheTableName: "message_cache",  // 对象存储(表)名称
  keyPath: "messages_id",             // 主键字段名
  indexs: [                  // 索引数组
    { name: "room_id", unique: false },
    {name:'room_id_timestamp',path:['room_id','messages_id'],unique:false},
  ]
}
const Room_Stream_Params = {
  dbName: "Room_Stream",       // 数据库名称
  cacheTableName: "room_stream",  // 对象存储(表)名称
  keyPath: "room_id",             // 主键字段名
}

const roominfocacheParams = {
  dbName: "Room_info",       // 数据库名称
  cacheTableName: "room_info_chache",  // 对象存储(表)名称
  keyPath: "room_id",
}
const users_infoParams = {
  dbName: "users_info",       // 数据库名称
  cacheTableName: "users_info_chache",  // 对象存储(表)名称
  keyPath: "user_id",
  indexs: [                  // 索引数组
    { name: "room_id", unique: false },
  ]
}

const room_stream = new ChatCacheDB(Room_Stream_Params)
const chat_cache = new ChatCacheDB(indexdbparams)
const room_info_cache = new ChatCacheDB(roominfocacheParams)
const users_info = new ChatCacheDB(users_infoParams)
await chat_cache.openDB()
await room_stream.openDB()
await room_info_cache.openDB()
await users_info.openDB()


app.provide('chat_cache', chat_cache)
app.provide('room_stream', room_stream)
app.provide('cacahe_room_info', room_info_cache)
app.provide('users_info_cache', users_info)

app.mount('#app')
